import { defineAsyncComponent } from 'vue'

export default {
  install(app) {
    const requireVueModules = import.meta.glob('./**/*.vue')
    const requireJsxModules = import.meta.glob('./**/*.jsx')
    for (const path in requireVueModules) {
      const componentPath = path.slice(0, path.indexOf('/index.vue'))
      const result = componentPath.slice(componentPath.lastIndexOf('/') + 1)
      const modulesContent = requireVueModules[path]
      app.component(result, defineAsyncComponent(modulesContent))
    }
    for (const path in requireJsxModules) {
      const componentPath = path.slice(0, path.indexOf('/index.jsx'))
      const result = componentPath.slice(componentPath.lastIndexOf('/') + 1)
      const modulesContent = requireJsxModules[path]
      app.component(result, defineAsyncComponent(modulesContent))
    }
  }
}
